]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
status/bluetooth: Show connected devices in subtitle
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 8 Feb 2023 13:31:10 +0000 (14:31 +0100)
committerMarge Bot <marge-bot@gnome.org>
Sat, 11 Feb 2023 20:44:07 +0000 (20:44 +0000)
Now that quick toggles support subtitles, use it to indicate connected
devices.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2501>

js/ui/status/bluetooth.js

index 4b828bd1ee5858b911555a3ae9350ad514c8f401..2851f2d270f5144c98441bd49484c79e9d61d972 100644 (file)
@@ -164,7 +164,27 @@ class BluetoothToggle extends QuickToggle {
             (bind, source) => [true, this._getIconNameFromState(source)],
             null);
 
+        this._client.connectObject(
+            'devices-changed', () => this._sync(),
+            this);
+
         this.connect('clicked', () => this._client.toggleActive());
+
+        this._sync();
+    }
+
+    _sync() {
+        const connectedDevices = [...this._client.getDevices()]
+            .filter(dev => dev.connected);
+        const nConnected = connectedDevices.length;
+
+        if (nConnected > 1)
+            /* Translators: This is the number of connected bluetooth devices */
+            this.subtitle = ngettext('%d Connected', '%d Connected', nConnected).format(nConnected);
+        else if (nConnected === 1)
+            this.subtitle = connectedDevices[0].alias;
+        else
+            this.subtitle = null;
     }
 
     _getIconNameFromState(state) {